package com.sihai.ehr.service.impl;

import com.sihai.core.*;
import com.sihai.ehr.model.biz.SalaryOvertime;
import com.sihai.ehr.service.OvertimeTaxService;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("overtimeTaxService")
public class OvertimeTaxServiceImpl implements OvertimeTaxService{

    @Resource
    private DataAccessor dataAccessor;
    
    @Override
    public void save(SalaryOvertime salaryOvertime) {
        if(salaryOvertime!=null)
            dataAccessor.save(salaryOvertime);
    }

    @Override
    public void remove(final String overtimeIds) {
        if(overtimeIds==null || overtimeIds.isEmpty())
            return;
        dataAccessor.batchUpdate(new QueryCreator(){
            @Override
            public Query createQuery(Session session) {
                return session.createQuery(String.format("delete from SalaryOvertime where id in (%s)",overtimeIds));
            }
        });
    }

    @Override
    public SalaryOvertime get(Long id) {
        if(id!=null)
            return dataAccessor.get(SalaryOvertime.class,id);
        return null;
    }

    @Override
    public LimitedList<SalaryOvertime> query(Long orgId, Limit limit, Sorter sorter) {
        return dataAccessor.findByHql(SalaryOvertime.class,"from SalaryOvertime ov where ov.organization.id=?", new Object[]{orgId},limit,sorter);
    }
}
